package uno.linze.wallpaper.domain.identity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import uno.linze.wallpaper.domain.identity.dto.UserRegister;
import uno.linze.wallpaper.domain.identity.entity.Users;
import uno.linze.wallpaper.domain.identity.repository.UserResponsitory;
import uno.linze.wallpaper.domain.identity.repository.impl.UserResponsitoryImpl;
import uno.linze.wallpaper.domain.identity.service.UsersService;
import uno.linze.wallpaper.domain.identity.mapper.UsersMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import uno.linze.wallpaper.domain.identity.service.ext.VerifyCodeService;

/**
* @author wangy
* @description 针对表【users(用户核心认证信息)】的数据库操作Service实现
* @createDate 2025-09-08 23:15:35
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService{

    @Autowired
    private UserResponsitoryImpl userResponsitoryImpl;

    @Autowired
    private VerifyCodeService verifyCodeService;

    @Override
    public void register(UserRegister userRegister) {

        //检查验证码是否正确/匹配邮箱
        if(!verifyCodeService.checkCode(userRegister.getEmail(), userRegister.getVerificationCode())) {
            throw new RuntimeException("验证码错误");
        }

        userResponsitoryImpl.register(userRegister.getUsername(), userRegister.getEmail(), userRegister.getPassword());
    }

    @Override
    public String login(String username, String password) {
        /// 尝试验证登录，成功则返回token

        return "";
    }
}
